$(function () {

})
/**
 * Created by King_Vicent on 2018/7/17.
 */
var vm = new Vue({
    el: '#rrapp',
    data:function() {
        return {
            isList: true, // 表格
            isDetail: false, // 详情
            isAdd: false, // 新增
            isSh: false, // 新增
            downloadButton: false, // 下载按钮
            downloadFilePath: "", // 下载按钮
            executeButton: false, // 执行督察
            tglx:false,
            qxlx:false,
            bhlx:false,
            zclx:false,
            sqbj:false,
            qxbj:false,
            bhbj:false,
            tgbj:false,
            viewReport:false,
            report:[{flag:'1',label:'简报'},{flag:'2',label:'祥报'}],
            reportClick:[],
            onAll: 'primary',
            onLx: '',
            onSp: '',
            tabName: '1',
            userInfo: '',
            bhyy: '',
            dclx: false,
            index: "",
            type: 0,
            searchProjectStatus:'',
            dcsp: false,
            lhzxtj: true,
            xz: false,
            dwqf: false,
            pageTitle: '立项基本', // 块标题
            createSteps: 0, // 步骤
            tableData: [], // 获取表格数据
            pageNo: 1, // 当前页
            totalPage: 0, // 总页数
            pageSize: 10, // 每页数据条数
            findKey: '', // 搜索关键字
            dataKind: null, // 数据类型
            baseForm: {
                id: '', // 立项id
                titleName: '', // 立项标题
                msgFlag: 1, // 是否短信通知
                dcssfs: 0, // 是否暗访
                dclx: 1,
                description: '', // 督察描述
                zbdw: '', // 主办单位
                zbdwId: '', // 主办单位Id
                ssfwCheckedList: [], // 选中单位
                jzrq: '', // 截止时间
                jzrqDate: '', // 截止时间
                startTime: '', // 开始时间
                startTimeDate: '', // 开始时间
                ids: [], // 选中单位的id
                modelId: '',// 选中模板的id
                file: ''
            },
            ssfwList: [],
            ssfwtxList: [],
            problemExpandedKeys: [], // 展开的单位类别
            problemCheckedKeys: [], // 选中的单位
            props: {
                children: 'children',
                label: 'label'
            },
            tplId: '', // 所选模板的id
            tplList: [{
                label: '标准模板',
                id: '1',
                children: []
            }, {
                label: '专项模板',
                id: '2',
                children: []
            },
            ], // 第二步 模板列表

            tplViewList: [], // 第二步 预览列表
            roleName: '',
            // 查看详情
            detailId: '',
            lookTitle: '', // 都查记录详情 标题
//            lookTime: '2018-04-29', // 都查记录详情 新增日期
            lookUpdateTime: '', // 都查记录详情 新增日期
            lookCorp: '', // 都查记录详情 单位
            lookStatus: '', // 都查记录详情 状态
            lookPercent: '', // 百分比
            lookJzrq: '', // 百分比
            lookDclx: 1, // 督查类型
            lookDcssfs: false, // 督查实施方式（0明察1暗访）
            lookStartTime: '', // 百分比
            lookProjectId: '', // 百分比
            itemInfos: '',
            modelList: [], // 督察模板
            modelName: '', // 督察模板标题
            modelViewExpandedKeys: [], // 查看时 展开的树节点
            historyData: [],// 督察记录
            historyDataSize: 0,// 督察记录总条数
            dwType: 0, // 选择条线单位或非条线单位
            pickerOptions0: {
                disabledDate:function(time) {
                    if (vm.baseForm.jzrqDate != undefined && vm.baseForm.jzrqDate != "" && vm.baseForm.jzrqDate != null) {
                        return time.getTime() > vm.baseForm.jzrqDate.getTime() || time.getTime() < Date.now() - 8.64e7;
                    }
                    return time.getTime() < Date.now() - 8.64e7;
                }
            },
            pickerOptions1: {
                disabledDate:function(time) {
                    if (vm.baseForm.startTimeDate != undefined && vm.baseForm.startTimeDate != "" && vm.baseForm.startTimeDate != null) {
                        return time.getTime() < vm.baseForm.startTimeDate.getTime()
                    }
                    return time.getTime() < (Date.now() - 8.64e7);
                }
            },
        }
    },
    mounted:function() {
        this.getData(this.type)
        this.getTxdwList()
        this.getFtxdwList()
    },
    methods: {
        TabHandleClick:function(tab) {
          console.log(tab.name);
          vm.tabName = tab.name;
          var url = '';
          if(tab.name == '1'){
            url = 'business/superviseproject/getProjectProcess';
          }else if(tab.name == '2'){
            url = 'business/superviseproject/getExecuteDept';
          }else if(tab.name == '3'){
            url = 'business/superviseproject/getSuperviseRecord';
          }else{
            return;
          }
          console.log(vm.tabName)
          vm.getTabDatasByName(url);
        },
        reportDownload:function() {
            var projectId = vm.lookProjectId
            console.log(vm.reportClick)
            window.location.href = baseURL + '/business/superviseproject/exportProjectFHReport?projectId=' + projectId;
            /*if(vm.reportClick.length == 1){
                if(vm.reportClick[0] == 1){
                    window.location.href = baseURL + '/business/superviseproject/exportProjectBriefReport?projectId=' + projectId;
                }else{
                    window.location.href = baseURL + '/business/superviseproject/exportProjectReport?projectId=' + projectId;
                }
            }else if(vm.reportClick.length == 2){
                window.location.href = baseURL + '/business/superviseproject/exportProjectBriefReport?projectId=' + projectId;
                window.location.href = baseURL + '/business/superviseproject/exportProjectReport?projectId=' + projectId;
            }else{
                    alert("请选择要下载的模板")
            }*/
        },
        getTabDatasByName:function(url){
            var params = {
                projectId: vm.lookProjectId
            }
            $.ajax({
                  type: "GET",
                  url: baseURL + url,
                  data: params,
                  contentType: "application/json",
                  success: function (res) {
                      if (res.code === '0') {
                          vm.historyData = res.data
                          vm.historyDataSize = res.data.length
                      } else {
                          alert(res.msg);
                      }
                  }
              });
        },
        alertMsg:function(item){
            var bhyy = '';
            if(item.czzt == '驳回立项'){
                bhyy = item.bhlxyy;
            }else if(item.czzt == '驳回办结'){
                bhyy = item.bhbjyy;
            }else{
                return;
            }
            this.$alert(bhyy, '驳回理由', {
                showConfirmButton:false,
                showClose:false,
                closeOnClickModal:true
            });
        },
        filterProjectStatus:function(value, row) {
        console.log(value)
            if(value == 21){
                return row.lxspzt == 2 && Date.parse(new Date()) < row.startTime;
            }else if(value == 22){
               return row.lxspzt == 2 && Date.parse(new Date()) > row.startTime;
            } else if (value == 23){
                return row.lxspzt == 2 && Date.parse(new Date()) > row.jzrq;
            }else{
                return row.lxspzt === value;
            }
        },
        selectTheFile:function(obj) {
//             debugger
//             layer.msg(1)
            // var objUrl = vm.getObjectURL(obj.files[0]);
            var fileName = $("#fileZxwd").val();
            if(null == fileName || '' == fileName){
                 return;
            }
            /*var r = /[+/?%=&#]/;
            if(aa.search(r) > -1){
                layer.msg(getMessageByCode("W30135"));
                return;
            }*/
            var f = fileName.split('.');
            var filePostfix = f[f.length-1];
            filePostfix = filePostfix.toUpperCase();
//            if(!(filePostfix == 'DOC' || filePostfix == 'DOCX')){//DOC
            if(filePostfix != 'DOC' && filePostfix != 'DOCX'){//DOC
                layer.msg("专项文档只能上传word格式文件");
                 return;
            }
            $("#fileText").val($("#fileZxwd").val());

        },
        // 获取数据
        getData:function(type) { // type 顶部按钮类型
            var params = {
                name: this.findKey,
                page: this.pageNo,
                type: type/*, // 类型
                projectStatus: 1, // 项目状态*/
            }
            $.ajax({
                type: "GET",
                url: baseURL + 'business/superviseproject/list',
                data: params,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.tableData = res.page.list
                        vm.totalPage = res.page.totalPage
                        vm.pangeNo = res.page.currPage
                        vm.baseForm.zbdw = res.sessionUser.deptName
                        vm.baseForm.zbdwId = res.sessionUser.deptId
                        vm.roleName = res.sessionUser.roleName
                        vm.dclx = RegExp(/B/).test(res.sessionUser.roleName)
                        vm.xz = vm.dclx
                        vm.dcsp = RegExp(/A/).test(res.sessionUser.roleName)
                        vm.userInfo = res.sessionUser
                    } else {
                        alert(res.msg);
                    }
                }
            });
        },

        // 搜索
        search:function(types, keys) {
            vm.pageNo = 1 // 当前页
            vm.getData(vm.type)
        },
        // 分页
        pageChange: function () {
            vm.getData(vm.type)
        },
        indexMethod:function(index){
            return (vm.pageNo - 1) * vm.pageSize + (index + 1);
        },
        // 按钮切换表格数据
        handleClick:function(type) {
            vm.findKey=''
            vm.type=type
            vm.pageNo = 1 // 当前页
            if (type === 0) {
                // 全部
                vm.getData('0')
                vm.isSh = false
                vm.onAll = 'primary'
                vm.onLx = ''
                vm.onSp = ''
            } else if (type === 1) {
                // 我的立项
                vm.getData('1')
                vm.isSh = false
                vm.onAll = ''
                vm.onLx = 'primary'
                vm.onSp = ''
            } else if (type === 2) {
                // 我的审批
                vm.getData('2')
                vm.isSh = true
                vm.onAll = ''
                vm.onLx = ''
                vm.onSp = 'primary'
            }
        },
        bhClick:function(czzt) {
            var title = '';
            if (czzt === 4) {
                title = '请输入驳回立项理由';
            } else if (czzt == 9) {
                title = '请输入驳回办结理由';
            }
            /*layer.prompt({title: title, formType: 2, area: ['800px', '350px']}, function (text, index) {
                vm.bhyy = text;
                vm.operationClick(czzt);
                layer.close(index);
            });*/
             this.$prompt('驳回理由', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                showClose:false,
                inputPattern: /[^s*$]/g,
                inputErrorMessage: '驳回理由不能为空！'
            }).then(({ value,action}) => {
                if (action == 'confirm'){
                    vm.bhyy = value,
                    vm.operationClick(czzt);
                }
            })
        },

        checkDate: function (beginDate, endDate) {
            var d1 = new Date(beginDate.replace(/\-/g, "\/"));
            var d2 = new Date(endDate.replace(/\-/g, "\/"));
            if (beginDate != "" && endDate != "" && d1 >= d2) {
                return false;
            } else {
                return true;
            }
        },
        getNowFormatDate: function () {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        },
        defaultCheckedTree:function(data){
            vm.$refs.ssfwTree.setCheckedKeys(data) // 获取选中数据
            vm.$refs.ssfwTxTree.setCheckedKeys(data) // 获取选中数据
            vm.handleCheckChange()
        },
        operationClick:function(czzt) {debugger;
            var projectId = vm.lookProjectId
            var updateParams = {}
            var czName = ''
            var title = '提示'
            switch (czzt) {
                case 1://再次申请立项findSuperviseProjectById
                    updateParams = {
                        id: projectId,
                        roleId: vm.userInfo.roleId
                    };
                    var fwIdsss = []
                    $.ajax({
                        type: "GET",
                        url: baseURL + '/app/project/findSuperviseProjectById',
                        data: updateParams,
                        async:false,
                        contentType: "application/json",
                        success: function (res) {
                            if (res.code === '0') {
                                // debugger;
                                console.log(res.data)
                                vm.baseForm.titleName = res.data.titleName
                                vm.baseForm.id = projectId
                                vm.baseForm.description = res.data.description
                                vm.baseForm.dcssfs = res.data.dcssfs - 0
                                // vm.baseForm.dclx = res.data.dclx - 0
                                vm.baseForm.msgFlag = res.data.msgFlag - 0
                                vm.baseForm.startTimeDate = new Date()
                                if (vm.checkDate(vm.getNowFormatDate(), res.data.jzrq)) {
//                                    vm.baseForm.jzrqDate = res.data.jzrq
                                    vm.baseForm.jzrqDate = new Date(res.data.jzrq.replace(/\-/g, "\/"))
                                }
                                vm.baseForm.modelId = res.data.modelId
                                vm.baseForm.dwType = res.data.projectStatus
//                                      ssfwCheckedList: [], // 选中单位
//                                           ids: [], // 选中单位的id
                                var checkedArr = []
                                var fwIds = []


                                if (res.data.projectMapList != undefined && res.data.projectMapList != "" && res.data.projectMapList != null) {
                                    for (var i = 0; i < res.data.projectMapList.length; i++) {
                                        // checkedArr.push(res.data.projectMapList[i].ssdwName)
                                        // fwIds.push(res.data.projectMapList[i].toSsdwId)

                                        checkedArr.push({
                                            label: res.data.projectMapList[i].ssdwName
                                        })
                                        fwIds.push({toSsdwId: res.data.projectMapList[i].toSsdwId})
                                        fwIdsss.push( res.data.projectMapList[i].toSsdwId)
                                    }
                                }


                                vm.isDetail = false
                                vm.isAdd = true
                                vm.isList = false
                                vm.changeDwType(res.data.projectStatus)
                                vm.changeLxlx(res.data.dclx - 0)

                                vm.baseForm.dclx = res.data.dclx - 0
                                // vm.baseForm.ssfwCheckedList = checkedArr
                                // vm.baseForm.ids = fwIds
                                // vm.$refs.ssfwTree.setCheckedKeys(fwIdsss)
                                vm.defaultCheckedTree(fwIdsss)
                                vm.updateHandleChooseTpl(res.data.modelId)
                                // vm.addProject ();
//                           vm.changeLxlx(vm.baseForm.dclx);
                            } else {
                                alert(res.msg);
                            }
                        }
                    });

                    return;
                case 2://取消立项
                    updateParams = {
                        id: projectId,
                        deleteFlag: 1,
                        userId: vm.userInfo.userId,
                        userDeptId: vm.userInfo.deptId,
                        userName: vm.userInfo.name,
                        czzt: czzt,
                        roleId: vm.userInfo.roleId
                    };
                    czName = '取消立项'
                    break;
                case 3://通过立项
                    updateParams = {
                        id: projectId,
                        userId: vm.userInfo.userId,
                        userDeptId: vm.userInfo.deptId,
                        userName: vm.userInfo.name,
                        czzt: czzt,
                        lxspzt: "2",
                        projectStatus: "1",
                        roleId: vm.userInfo.roleId
                    };
                    czName = '通过立项'
                    break;
                case 4://驳回立项
                    updateParams = {
                        id: projectId,
                        lxspzt: "1",
                        bhlxyy: vm.bhyy,
                        userId: vm.userInfo.userId,
                        userDeptId: vm.userInfo.deptId,
                        userName: vm.userInfo.name,
                        czzt: czzt,
                        roleId: vm.userInfo.roleId
                    };
                    czName = '驳回立项'
                    title = '驳回理由'
                    break;
                case 5://执行督察
                    layer.msg("立项需要在app上执行！");

                    return;
                    /*vm.index = layer.open({
                        title : "新增执行记录",
                        type : 2,
                        fixed: true,
                        shadeClose: true,
                        area : [ "100%", "100%" ],
                        content : baseURL + '/business/supervise/addRecord?id='+vm.lookProjectId
                    });*/
                    return;
                case 6://申请办结
                    updateParams = {
                        id: projectId,
                        projectStatus: "2",
                        lxspzt: "3",
                        userId: vm.userInfo.userId,
                        userDeptId: vm.userInfo.deptId,
                        userName: vm.userInfo.name,
                        czzt: czzt,
                        roleId: vm.userInfo.roleId
                    };
                    czName = '申请办结'
                    break;
                case 7://取消办结
                    updateParams = {
                        id: projectId,
                        projectStatus: "1",
                        lxspzt: "2",
                        userId: vm.userInfo.userId,
                        userDeptId: vm.userInfo.deptId,
                        userName: vm.userInfo.name,
                        czzt: czzt,
                        roleId: vm.userInfo.roleId
                    };
                    czName = '取消办结'
                    break;
                case 8://通过办结
                    updateParams = {
                        id: projectId,
                        projectStatus: "3",
                        lxspzt: "5",
                        userId: vm.userInfo.userId,
                        userDeptId: vm.userInfo.deptId,
                        userName: vm.userInfo.name,
                        czzt: czzt,
                        roleId: vm.userInfo.roleId
                    };
                    czName = '通过办结'
                    break;
                case 9://驳回办结
                    updateParams = {
                        id: projectId,
                        projectStatus: "1",
                        lxspzt: "4",
                        bhbjyy: vm.bhyy,
                        userId: vm.userInfo.userId,
                        userDeptId: vm.userInfo.deptId,
                        userName: vm.userInfo.name,
                        czzt: czzt,
                        roleId: vm.userInfo.roleId
                    };
                    czName = '驳回办结'
                    title = '驳回理由'
                    break;
            }
            this.$confirm('确认是否' + czName + "?", title, {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      showClose:false,
                    }).then(action => {
                        if(action == 'confirm'){
                            $.ajax({
                                type: "GET",
                                url: baseURL + '/app/project/updateSuperviseProject',
                                data: updateParams,
                                contentType: "application/json",
                                success: function (res) {
                                    if (res.code === '0') {
                                        if(czzt == 2){//取消立项则删除该立项跳转到列表页面
                                            vm.cancel();
                                            vm.getData();
                                        } else {
                                             vm.updateDetailView(projectId);
                                        }

                                        layer.msg("操作成功！");
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        }


                    });
            /*layer.confirm("是否确定" + czName, function (index) {
                $.ajax({
                    type: "GET",
                    url: baseURL + '/app/project/updateSuperviseProject',
                    data: updateParams,
                    contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            layer.msg("操作成功！");

                        } else {
                            alert(res.msg);
                        }
                    }
                });
            })*/
        },

        // 查看立项详情
//        download(index, row) {
        download:function() {
            var fullUrl = vm.downloadFilePath
            var u = encodeURI(fullUrl);
            window.location.href = baseURL + '/app/common/file/downloadfile?path=' + u;
        },
        download1:function(index, row) {
            var fullUrl = row.filePath
            var u = encodeURI(fullUrl);
            window.location.href = baseURL + '/app/common/file/downloadfile?path=' + u;
        },
        updateDetailView:function(projectId) {

            var params = {
                projectId: projectId
            }
            vm.tglx=false,
            vm.qxlx=false,
            vm.bhlx=false,
            vm.zclx=false,
            vm.sqbj=false,
            vm.qxbj=false,
            vm.bhbj=false,
            vm.tgbj=false,
             $.ajax({
                type: "GET",
                url: baseURL + 'business/superviseproject/detail',
                data: params,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.handleView(1,res.detail);
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
        },
        handleView:function(index, row) {debugger
            vm.pageTitle = '项目详情'
            vm.isDetail = true
            vm.isAdd = false
            vm.isList = false
            vm.lookTitle = row.titleName
            vm.tabName = '1'
            vm.lookProjectId = row.id
            vm.lookUpdateTime = row.lxrq
            vm.lookCorp = row.userDeptName
            vm.downloadFilePath = row.filePath
            if (row.filePath != '' && row.filePath != null) {
                console.log(row.filePath)
                vm.downloadButton = true
            }
            if (row.projectStatus === '1' && (row.lxspzt === '2' || row.lxspzt === '4') && RegExp("\""+row.dqdw+"\"").test(row.projectJsonInfo) && (Date.parse(new Date()) > row.startTime)) {
                vm.executeButton = true
            }
            //通过立项 驳回立项
            if(row.projectStatus === '0' && row.lxspzt === '0' && RegExp("A").test(row.role)){
                vm.tglx = true
                vm.bhlx = true
            }
            //取消立项
            if(row.projectStatus === '0' && row.lxspzt === '0' && RegExp("B").test(row.role)){
                vm.qxlx = true
            }
            //再次立项
            if(row.projectStatus === '0' && row.lxspzt === '1' && RegExp("B").test(row.role)){
                vm.zclx = true
            }
            //申请办结
            if(row.projectStatus === '1' && (row.lxspzt === '2' || row.lxspzt === '4') && RegExp("B").test(row.role) && (Date.parse(new Date()) > row.jzrq)){
                vm.sqbj = true
            }
            //取消办结
            if(row.projectStatus === '2' && row.lxspzt === '3' && RegExp("B").test(row.role) && (Date.parse(new Date()) > row.jzrq)){
                vm.qxbj = true
            }
            //驳回办结
            //通过办结
            if(row.projectStatus === '2' && row.lxspzt === '3' && RegExp("A").test(row.role)){
                vm.bhbj = true
                vm.tgbj = true
            }

            vm.lookDclx = row.dclx
            if (row.dcssfs == 1) {
                vm.lookDcssfs = true
            }
            vm.lookStartTime = dateFtt("yyyy-MM-dd hh:mm", new Date(row.startTime))
            vm.lookJzrq = dateFtt("yyyy-MM-dd hh:mm", new Date(row.jzrq))
            switch (row.lxspzt) {
                case '0' :
                    vm.lookStatus = '立项中';
                    break;
                case '1' :
                    vm.lookStatus = '立项已驳回';
                    break;
                case '2' :
                    if (Date.parse(new Date()) < row.startTime) {
                        vm.lookStatus = '未开始';
                    } else if (Date.parse(new Date()) > row.startTime && Date.parse(new Date()) < row.jzrq) {
                        vm.lookStatus = '进行中';
                    } else if (Date.parse(new Date()) > row.jzrq){
                        vm.lookStatus = '已截止';
                    }
                    break;
                case '3' :
                    vm.lookStatus = '办结中';
                    break;
                case '4' :
                    vm.lookStatus = '办结已驳回';
                    break;
                case '5' :
                    vm.lookStatus = '已办结';
                    break;
                default :
                    vm.lookStatus = '未知<';
                    break;
            }
            vm.lookPercent = Math.round(row.dcnum / row.allnum * 10000) / 100.00 + "%"
            vm.itemInfos = row.description
            vm.viewModelInfo(row.modelId)
            vm.modelName = row.mbmc
            var params = {
                projectId: row.id
            }
            var url = 'business/superviseproject/getProjectProcess'
            // ajax 三个接口
            vm.getTabDatasByName(url)
        },

        // 获取要查看模板的信息
        viewModelInfo: function (id) {
            var url = 'business/supervisetemplet/findModelStandardListTree1?id=' + id
            $.ajax({
                type: "GET",
                url: baseURL + url,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.modelList = res.list
                        vm.modelViewExpandedKeys = []
                        for (var i in vm.modelList) {
                            var first = vm.modelList[i]
                            vm.modelViewExpandedKeys.push(first.id)
                            if (first.children !== []) {
                                for (var j in first.children) {
                                    var second = first.children[j]
                                    vm.modelViewExpandedKeys.push(second.id)
                                    if (second.children !== []) {
                                        for (var k in second.children) {
                                            var third = second.children[k]
                                            if (third.children !== []) {
                                                vm.modelViewExpandedKeys.push(third.id)
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        alert(res.msg);
                    }
                }
            });
        },

        // 点击查看督查记录
        handleViewHistory:function(val) {
            layer.open({
                 title : '督察记录',
                 type : 2,
                 fixed: true,
                 shadeClose: true,
                 area : [ "100%", "100%" ],
                 content : baseURL + '/business/supervise/recordDetails?id='+val + "&type=" +1
             });
            // ajax
        },
        // 执行立项
        activeProject:function() {
            var params = {
                id: vm.detailId
            }
            // ajax
        },

        // 新增立项
        addProject:function() {
            vm.isDetail = false
            vm.isAdd = true
            vm.isList = false
            vm.changeDwType(0)
        },
        checkLength:function() {
        // debugger;
            console.log(vm.baseForm.titleName)
            console.log(vm.baseForm.titleName.length)
            if (vm.baseForm.titleName.length > 16) {
                layer.msg("立项标题长度不能超过16个中文字符")
                return true;
            }
        },

        // 切换短信通知radio状态
        changeMessage:function(e) {
            e === vm.baseForm.msgFlag ? vm.baseForm.msgFlag = '' : vm.baseForm.msgFlag = e
        },
        // 切换暗访radio状态
        changeAf:function(e) {
            e === vm.baseForm.dcssfs ? vm.baseForm.dcssfs = '' : vm.baseForm.dcssfs = e
        },
        // 切换立项类型
        changeLxlx:function(e) {
            vm.getFtxdwList()
            vm.getTxdwList()
            // vm.$refs.ssfwTree.setCheckedKeys([])// 获取选中数据
            // // this.$refs.ssfwTree.setCheckedKeys([]);
            // vm.$refs.ssfwTxTree.setCheckedKeys([])// 获取选中数据
            // vm.problemCheckedKeys=[]
            e === vm.baseForm.dclx ? vm.baseForm.dclx = '' : vm.baseForm.dclx = e
            switch (e) {
                case 1://常规专项查督察条线
                    vm.dwqf = false
                    vm.baseForm.ssfwCheckedList = []
                    vm.changeDwType(0)
                    break;
                case 2://联合专项
                    vm.dwqf = true
                    vm.baseForm.ssfwCheckedList = []
                    vm.changeDwType(0)
                    break;
                case 3://自查专项查非督察条线
                    vm.dwqf = false
                    vm.baseForm.ssfwCheckedList = []
                    vm.changeDwType(1)
                    break;
            }

        },
        getTxdwList:function() {
            var url = baseURL + 'business/instructions/getDept'
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: {'sfdctx': '0'},
                success: function (res) {
                    if (res.code === '0') {
                        vm.ssfwtxList = res.data
                    } else {
                        vm.ssfwtxList = []
                    }
                }
            })
        },
        getFtxdwList:function() {
            var url = baseURL + 'business/instructions/getAllOtherDept'
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: {'sfdctx': '0'},
                success: function (res) {
                    if (res.code === '0') {
                        vm.ssfwList = res.data
                    } else {
                        vm.ssfwList = []
                    }
                }
            })
        },
        // 切换条线/非条线单位
        changeDwType:function(e) {
            // const loadingChange = this.$loading({
            //     lock: true,
            //     text: '正在刷新单位列表信息，请稍候！',
            //     target: document.querySelector('.view-tree')
            // });
            vm.dwType = e
            // console.log(e)
            // loadingChange.close()
            /*    var url = e === 0 ? baseURL + 'business/instructions/getDept' : baseURL + 'business/instructions/getAllOtherDept'

                $.ajax({
                    url: url,
                    type: 'post',
                    dataType: 'json',
                    data: {'sfdctx': '0'},
                    success: function (res) {
                        if (res.code === '0') {
                            if (e === 0) {
                                vm.ssfwtxList = res.data
                            } else {
                                vm.ssfwList = res.data
                            }
                            loadingChange.close()
                        } else {
                            if (e === 0) {
                                vm.ssfwtxList = []
                            } else {
                                vm.ssfwList = []
                            }
                            loadingChange.close()
                        }
                    }
                })*/
        },

        // 选择单位
        handleCheckChange:function(data, checked, indeterminate) { // arguments:对象、节点本身是否被选中、节点的子树中是否有被选中的节点
            var checkedNodes = vm.$refs.ssfwTree.getCheckedNodes() // 获取选中数据
            var checkedTxNodes = vm.$refs.ssfwTxTree.getCheckedNodes() // 获取选中数据
            var checkedData = checkedNodes // 定义新选中变量不操作原数据
            var checkedTxData = checkedTxNodes // 定义新选中变量不操作原数据
            var checkedArr = []
            var fwIds = []
            var j = 0;
            var k = 0;

            for (var i in checkedData) {
                if (checkedData[i].children.length === 0) {
                    checkedArr.push({
                        label: checkedData[i].label
                    })
                    fwIds.push({toSsdwId: checkedData[i].deptId, ssdwName: checkedData[i].label,sfdctx:"2"})
                }
                j = 1;
                ;
            }
            for (var i in checkedTxData) {
                if (checkedTxData[i].children.length === 0) {
                    checkedArr.push({
                        label: checkedTxData[i].label
                    })
                    fwIds.push({toSsdwId: checkedTxData[i].deptid, ssdwName: checkedTxData[i].label,sfdctx:"1"})
                }
                k = 1;
            }
            vm.lhzxtj = (j + k) == 2 ? false : true
            vm.baseForm.ssfwCheckedList = checkedArr
            vm.baseForm.ids = fwIds
        },

        // 选择模板
        handleChooseTpl:function(nodeData) { // nodeData包含所点击节点的所有数据
            if (nodeData.children.length === 0) {
                vm.baseForm.modelId = nodeData.id
                var url = 'business/supervisetemplet/findModelStandardListTree1?id=' + vm.baseForm.modelId
                $.ajax({
                    type: "GET",
                    url: baseURL + url,
                    contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            vm.tplViewList = res.list
                        } else {
                            alert(res.msg);
                        }
                    }
                });
            }
            /*$.ajax({
             type: "GET",
             url: '',
             contentType: "application/json",
             success: function (res) {
             if (res.code === '0') {
             vm.tplViewList = res.data // 将模板详情赋值给预览部分的树组件
             } else {
             alert(res.msg);
             }
             }
             });*/
        },
        // 选择模板
        updateHandleChooseTpl:function(id) { // nodeData包含所点击节点的所有数据
                vm.baseForm.modelId = id
                var url = 'business/supervisetemplet/findModelStandardListTree1?id=' + vm.baseForm.modelId
                $.ajax({
                    type: "GET",
                    url: baseURL + url,
                    contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            vm.tplViewList = res.list
                        } else {
                            alert(res.msg);
                        }
                    }
                });
            /*$.ajax({
             type: "GET",
             url: '',
             contentType: "application/json",
             success: function (res) {
             if (res.code === '0') {
             vm.tplViewList = res.data // 将模板详情赋值给预览部分的树组件
             } else {
             alert(res.msg);
             }
             }
             });*/
        },

        // 取消
        cancel:function() {
            if (vm.createSteps === 2) {
                vm.pageTitle = '模板选择'
                vm.createSteps = 1
            } else if (vm.createSteps === 1) {
                vm.pageTitle = '立项选择'
                vm.createSteps = 0
                vm.tplViewList = []
            } else if (vm.createSteps === 0) {
                vm.backList()
            }

        },

        //返回立项列表页面
        backList:function() {debugger
            vm.pageTitle = '立项选择'
            vm.tplViewList = []
            vm.createSteps = 0
            vm.isDetail = false
            vm.isAdd = false
            vm.isList = true
            vm.executeButton=false, // 执行督察
            vm.tglx=false,
            vm.qxlx=false,
            vm.bhlx=false,
            vm.zclx=false,
            vm.sqbj=false,
            vm.qxbj=false,
            vm.bhbj=false,
            vm.tgbj=false,
            $("#fivarext").val("")
            $("#fileZxwd").val("")
            vm.changeLxlx(1)
//            vm.defaultCheckedTree()
            vm.baseForm = {
                id: '', // 立项id
                titleName: '', // 立项标题
                msgFlag: 1, // 是否短信通知
                dcssfs: 0, // 是否暗访
                dclx: 1,
                description: '', // 督察描述
                zbdw: vm.baseForm.zbdw, // 主办单位
                zbdwId: vm.baseForm.zbdwId, // 主办单位Id
                ssfwCheckedList: [], // 选中单位
                jzrq: '', // 截止时间
                jzrqDate: '', // 截止时间
                startTime: '', // 开始时间
                startTimeDate: '', // 开始时间
                ids: [], // 选中单位的id
                modelId: '',// 选中模板的id
                file: ''
            }
        },

        // 下一步
        nextStep:function() {
            if (vm.createSteps === 0) {
                if (vm.baseForm.titleName === '') {
                    alert("标题不能为空！");
                    return;
                }
                if (vm.checkLength()) {
                    return;
                }
                if (vm.baseForm.description === '') {
                    alert("督察描述不能为空！");
                    return;
                }

                if (vm.baseForm.startTimeDate === '') {
                    alert("开始时间不能为空！");
                    return;
                }
                if (vm.baseForm.jzrqDate === '') {
                    alert("截止时间不能为空！");
                    return;
                }
                if (vm.baseForm.dclx == 2 && vm.lhzxtj) {
                    alert("联合专项时督察单位和非督察单位都必须有值！");
                    return;
                }
                if (vm.baseForm.ids.length === 0) {
                    alert("立项执行单位不能为空！");
                    return;
                }
                vm.pageTitle = '模板选择'
                vm.createSteps = 1
                vm.tplList = [{
                    label: '标准模板',
                    id: '1',
                    children: []
                }, {
                    label: '专项模板',
                    id: '2',
                    children: []
                }]
                vm.getAllModel()
            } else if (vm.createSteps === 1) {

                vm.pageTitle = '提交审核'
                vm.createSteps = 2
            }
        },

        getAllModel:function() {
            $.ajax({
                type: "GET",
                url: baseURL + 'business/superviseproject/findAllModel',
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        for (var i in res.data) {
                            var model = res.data[i]
                            var modelObject = {id: '', label: '', children: []}
                            if (model.mblx === '0') {
                                modelObject.id = model.id
                                modelObject.label = model.mbmc
                                vm.tplList[0].children.push(modelObject)
                            } else {
                                modelObject.id = model.id
                                modelObject.label = model.mbmc
                                vm.tplList[1].children.push(modelObject)
                            }
                        }

                    } else {
                        alert(res.msg);
                    }
                }
            });
        },
        // 提交审批
        commit:function() {
            // debugger

            if (vm.baseForm.modelId === '') {
                alert("请选择立项模板！");
                return;
            }
            var lxlxName = "常规立项？";
            switch (vm.baseForm.dclx) {
                case 1:
                    lxlxName = "常规立项？";
                    break;
                case 2:
                    lxlxName = "联合督察立项？";
                    break;
                case 3:
                    lxlxName = "自查立项？";
                    break;
                default:
                    alert("立项类型不正确！");
                    return;
            }
            layer.confirm("是否确定新增" + lxlxName, function (index) {
                // debugger;
                vm.baseForm.ids = JSON.stringify(vm.baseForm.ids)
                vm.baseForm.jzrq = dateFtt('yyyy-MM-dd hh:mm:ss', vm.baseForm.jzrqDate)
                vm.baseForm.startTime = dateFtt('yyyy-MM-dd hh:mm:ss', vm.baseForm.startTimeDate)
                // vm.baseForm.file=$("#fileZxwd")[0].files[0]
                var formData = new FormData();
                formData.append("ids", vm.baseForm.ids)
                formData.append("id", vm.baseForm.id)
                formData.append("startTime", vm.baseForm.startTime)
                formData.append("titleName", vm.baseForm.titleName)
                formData.append("msgFlag", vm.baseForm.msgFlag)
                formData.append("dcssfs", vm.baseForm.dcssfs)
                formData.append("dclx", vm.baseForm.dclx)
                formData.append("description", vm.baseForm.description)
                formData.append("zbdw", vm.baseForm.zbdw)
                formData.append("zbdwId", vm.baseForm.zbdwId)
                formData.append("ssfwCheckedList", vm.baseForm.ssfwCheckedList)
                formData.append("jzrq", vm.baseForm.jzrq)
                formData.append("jzrqDate", vm.baseForm.jzrqDate)
                formData.append("jzrqDate", vm.baseForm.startTime)
                formData.append("startTimeDate", vm.baseForm.startTimeDate)
                formData.append("modelId", vm.baseForm.modelId)

                formData.append("file", $("#fileZxwd")[0].files[0])

                // var params =vm.baseForm
                var params = formData
                // console.log(params)
                $.ajax({
                    type: 'post',
                    url: baseURL + 'business/superviseproject/insertSuperviseProject',
                    data: params,
                    processData: false,  //tell jQuery not to process the data
                    contentType: false,  //tell jQuery not to set contentType
                    // contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            // 成功后的动作
                            vm.createSteps = 0
                            alert("立项新增成功！");
                            vm.backList()
                            vm.getData()
                            // ...
                        } else {
                            alert(res.msg);
                        }
                        layer.close(index);
                    }
                });

            });
        },

        // 过滤状态
        formatStatus: function (row, column) {
            // debugger
            /*switch (row.projectStatus) {
                case '0' :
                    return '立项中';
                case '1' :
                    return '进行中';
                case '2' :
                    return '办结中';
                case '3' :
                    return '已办结';
                default :
                    return '未知<';
            }*/
            switch (row.lxspzt) {
                case '0' :
                    return '立项中';
                case '1' :
                    return  '立项已驳回';
                case '2' :
                    if (Date.parse(new Date()) < row.startTime) {
                        return '未开始';
                    } else if (Date.parse(new Date()) > row.startTime && Date.parse(new Date()) < row.jzrq) {
                        return '进行中';
                    } else if (Date.parse(new Date()) > row.jzrq){
                        return '已截止';
                    }
                    break;
                case '3' :
                    return '办结中';
                case '4' :
                    return '办结已驳回';
                case '5' :
                    return '已办结';
                default :
                    return '未知<';
            }

        },


        formatMath: function (row, column) {
            return row.allnum == 0 ? "0%" : Math.round(row.dcnum / row.allnum * 10000) / 100.00 + "%";
        },
        // 过滤时间
        formatTime: function (row, column) {
            return dateFtt("yyyy-MM-dd hh:mm", new Date(row.startTime));
        },
        // 过滤时间
        formatTime1: function (row, column) {
            return dateFtt("yyyy-MM-dd hh:mm", new Date(row.jzrq));
        },
        getObjectURL:function(file) {
            var url = null;
            if (window.createObjectURL != undefined) { // basic
                url = window.createObjectURL(file);
            } else if (window.URL != undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
        }
    }
})
